import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class BrowseWebPage extends JFrame{
	private JTextField adressBar;
    private JEditorPane display;
    //constructor
    public BrowseWebPage() {
        super("Browser");
        
        adressBar = new JTextField("enter a URL host");
        adressBar.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent evt) {
                loadPage(evt.getActionCommand());
            }
        });
        add(adressBar, BorderLayout.NORTH);
        
        display = new JEditorPane();
        display.setEditable(false);
        display.addHyperlinkListener(new HyperlinkListener() {

            @Override
            public void hyperlinkUpdate(HyperlinkEvent hevt) {
                if (hevt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    loadPage(hevt.getURL().toString());
                }
            }
        });
        
        add(new JScrollPane(display), BorderLayout.CENTER);
        setSize(500, 300);
        setVisible(true);
    }
    
    private void loadPage(String userText) {
        try {
            display.setPage(userText);
            adressBar.setText(userText);
        } catch (Exception ex) {}
    }
}
